using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

public class WheatManager : MonoBehaviour
{
    public List<GameObject> WheatGameObjects = new List<GameObject>();
    private Dictionary<GameObject, float> WheatTimeDown = new Dictionary<GameObject, float>();


    void Update()
    {
        List<GameObject> completeList = new List<GameObject>();
        Dictionary<GameObject,float> TempDictionary = new Dictionary<GameObject, float>();
        foreach (var keyvalue in WheatTimeDown)
        {
            var timeDown = keyvalue.Value;
            var e = timeDown - Time.deltaTime;
            if (e <= 0)
            {
                keyvalue.Key.transform.GetChild(0).DOScale(1, 0.1f);
                keyvalue.Key.transform.GetChild(1).DOScale(1, 0.1f);
                completeList.Add(keyvalue.Key);
            }
            else
            {
                TempDictionary.Add(keyvalue.Key,e);
            }
        }

        foreach (var temp in TempDictionary)
        {
            WheatTimeDown[temp.Key] = temp.Value;
        }

        foreach (var completeObject in completeList)
        {
            WheatTimeDown.Remove(completeObject);
        }
    }

    public void HookWheat(GameObject wheat)
    {
        if (!WheatTimeDown.ContainsKey(wheat))
        {
            wheat.transform.GetChild(0).DOScale(0, 0.1f);
            wheat.transform.GetChild(1).DOScale(0, 0.1f);
        }
    }

    public void HookWheatLeave(GameObject wheat)
    {
        WheatTimeDown[wheat] = 5f;
    }
}
